﻿using System.Linq;
using CCS.BLL;
using CCS.BLL.Impl;
using CIK.Framework.Diagnostics;

namespace CCS.WebApp.ViewModels.Category.Builders.Impl
{
    public class HomePageListVmBuilder : IHomePageListVmBuilder
    {
        private readonly ICategoryManager _categoryManager;
        private readonly IItemManager _itemManager;

        public HomePageListVmBuilder() : this(new CategoryManager(), new ItemManager())
        {
        }

        public HomePageListVmBuilder(ICategoryManager categoryManager, IItemManager itemManager)
        {
            _categoryManager = categoryManager;
            _itemManager = itemManager;
        }

        public CategoryListViewModel CategoryListVmBuild(int categoryId)
        {
            Throw.IfArgumentNull(_categoryManager, "CategoryManager");

            var categoryListVm = new CategoryListViewModel();

            categoryListVm.Categories = _categoryManager.GetAll().ToList();
            categoryListVm.Category = _categoryManager.GetById(categoryId);
            categoryListVm.Items = _itemManager.GetItemByCategoryId(categoryId).ToList();

            return categoryListVm;
        }
    }
}